// import {MapManager as  OpenLayersMap} from "@/components/cme-base2D/core/MapManager";
import { useGeoJsonManager } from "@/utils/autoImprotJson.ts";
// import RYProgress from "../components/RYprogress/index.vue";

import { fromLonLat } from "ol/proj";
export default defineComponent({
  // components: { RYProgress },
  setup(props) {
    // 创建响应式状态
    const state = reactive({
      showDialog: false,
      contentInfo: {},
      tabsActive: "qs",
    });

    const olService = OpenLayersMap.getInstance();
    const {
      geoJsonData,
      getProvinceData,
      getAllDistrictData,
      getDistrictData,
      getAllAreaData,
    } = useGeoJsonManager({
      province: ["安徽省"],
      district: ["anhui"],
      area: [
        "340000",
        "340100",
        "340200",
        "340300",
        "340400",
        "340500",
        "340600",
        "340700",
        "340800",
        "341000",
        "341100",
        "341200",
        "341300",
        "341500",
        "341600",
        "341700",
        "341800",
      ],
    });
    // 加载地图json
    const fetchData = async () => {
      await new Promise((resolve) => {
        const interval = setInterval(() => {
          if (Object.keys(geoJsonData.value.province).length > 0) {
            clearInterval(interval);
            resolve(null);
          }
        }, 100);
      });

      let levelOptions = { maxLevel: 8, minLevel: 6 };
      // olService.create_boundary(
      //   [getProvinceData("安徽省")],
      //   "0",
      //   false,
      //   levelOptions
      // );
      olService.create_annotation(getAllAreaData(), "1", false, levelOptions);
    };
    const methods = {
      onCancel() {
        state.showDialog = false;
      },
      getHomeworkInformation(type) {
        switch (type) {
          case 1:
            return {
              type: "danger",
              name: "作业中",
            };
          case 2:
            return {
              type: "success",
              name: "作业完成",
            };
          case 3:
            return {
              type: "warning",
              name: "准备中",
            };
          default:
            break;
        }
      },
      onClickTab(value) {
        if (value.name == "wdwd") {
        } else {
        }
      },
    };
    onMounted(() => {
      fetchData();
      setTimeout(() => {
        olService.createSingleClickEvent((value) => {
          if (value.properties) {
            state.contentInfo = value.properties;
            state.showDialog = true;
          } else {
            methods.onCancel();
          }
        }, false);
      }, 300);
    });
    return {
      ...toRefs(state),
      ...methods,
    };
  },
});
